<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="" style="height:1000rpx;">
		<view class="employee-list-content">
			<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
			<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
			<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
				<view class="" slot="top" >
					<view class="shop-header">
						<view class="u-p-20">
							<u-search :searchIconFlag="true" v-model="searchValue" input-align="center" placeholder="关键字筛选" height="70" :border-color="'#FFBB1A'" :bg-color="'#fff'" 	
							:show-action="false" @change="reloadFn" @search="reloadFn"></u-search>
						</view>
					</view>
				</view>
				<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
				
				<view class="payorder-container" v-for="(item,index) in dataList" :key="index" >
					<view class="payorder-section">
						<!-- <image :src="item.headImg?item.headImg:defaultLogo" mode="" class="section-image" ></image> -->
						<view class="section-list">
							<view class="section-item u-flex u-row-between">
								<view class="section-item-name u-line-2 u-flex-1" style="overflow: hidden;">{{item.name}}</view>
								<view class="u-m-l-30 section-btn u-flex u-row-center"  v-if="chooseTagIds.indexOf(item.id)!==-1">
									<u-icon name="checkbox-mark" color="green" size="40"></u-icon>
								</view>
								<view  v-else class="section-btn" @tap="itemClick(item,index)">选择</view>
							</view>
						</view>
					</view>
				</view>
				
				<view class="" slot="bottom" >
					<view class="shop-header">
						<view class="u-p-20">
							<view class="confrim-btn" @tap="sendData()">确定</view>
						</view>
					</view>
				</view>
			</z-paging>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				searchValue:'',
				chooseTagIds:[],
				chooseTag:[],
			}
		},
		props:{
			initData:{
				type:Array,
				default:[]
			},
			type:{
				type:[Number,String],
				default:0
			},
		},
		created(){
			this.chooseTag=this.initData;
			// this.$refs.paging.reload();
			this.chooseTagIds = this.chooseTag.map(item=>{
				return item.id;
			})
		},
		methods: {
			reloadFn(){
				this.$refs.paging.reload();
			},
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					StatisticalOption:this.type,
				}
				if(this.searchValue!==''){
					params.name = this.searchValue;
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/v1.2/Chart/SellerGetStatisticalOptions', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
			clearChooseFn(){
				this.chooseTagIds = [];
				this.chooseTag = [];
			},
			itemClick(item,index) {
				if(this.chooseTagIds.length>=6){
					this.$u.toast('最多选择6个标签');
					return;
				}
				this.chooseTagIds.push(item.id);
				this.chooseTag.push(item);
				console.log(this.chooseTagIds);
				// this.$emit('choose',item)
			},
			sendData(){
				 this.$emit('choose',this.chooseTag)
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.employee-list-content {
		// min-height: 500rpx;
		height: 100%;
		.confrim-btn{
			padding: 25rpx 0;
			text-align: center;
			border-radius: 45rpx;background-color: #ffbb1a;border: none;
		}
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 30rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 30rpx 0;
			border-bottom: solid 1px #eaeaea;
			.section-image{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
			}
			.section-list{
				flex: 1;
				margin-left: 20rpx;
				.section-item{
					width: 100%;
					.section-item-name{
						flex:1;
					}
					.section-btn{
						width: 100rpx;
						margin: 0;
						height: 50rpx;
						line-height: 50rpx;
						border: 1rpx solid #eaeaea;
						border-radius: 15rpx;
						text-align: center;
					}
				}
			}
			
		}
		
	}


</style>
